{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Convert a jsonl file of non-augmented JavaScript programs into a list of sets format, but without augmentation (only 1 variant)**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%cd /work/paras/code/contracode\n",
    "%pwd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "import jsonlines\n",
    "import pickle\n",
    "import tqdm\n",
    "import gzip\n",
    "\n",
    "from representjs.data.jsonl_dataset import _make_example\n",
    "\n",
    "data_path = \"data/codesearchnet_javascript/javascript_dedupe_definitions_nonoverlap_v2_train.jsonl.gz\"\n",
    "out_path = \"data/codesearchnet_javascript/javascript_nonaugmented_train.pickle.gz\"\n",
    "!rm \"{out_path}\"\n",
    "\n",
    "examples = []\n",
    "with gzip.open(data_path, \"rb\") as f:\n",
    "    reader = jsonlines.Reader(f)\n",
    "    \n",
    "    for json_dict in tqdm.tqdm(reader, desc=\"reading\"):\n",
    "        example = _make_example(json_dict, fields={\"function\": \"function\"}, require_fields=[\"function\"], src_function_key=\"function\", src_method_name_key=\"identifier\")\n",
    "        if example:\n",
    "            s = [example[\"function\"]]\n",
    "            examples.append(s)\n",
    "\n",
    "with gzip.open(out_path, \"wb\") as out_f:\n",
    "    pickle.dump(examples, out_f, protocol=pickle.HIGHEST_PROTOCOL)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
